package com.yanqu.road.server.cmd.activity.newyear2023.redpacket;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FireWorkProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.newyear2023.FireWorkModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.S_FIREWORK_RP_TABLE, desc = "请求桌子")
public class FireWorkTableCmd extends AbstractCommand {

    private int activityId;
    private boolean isGetGhost;
    FireWorkProto.FireWorkRedPacketTableReqMsg reqMsg;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = FireWorkProto.FireWorkRedPacketTableReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        isGetGhost = reqMsg.getIsGetGhost();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        int resRet = player.getModule(FireWorkModule.class).checkCommon(activityId,2);
        if(resRet != 0){
            ret = resRet;
            return;
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            FireWorkProto.FireWorkRedPacketTableRespMsg.Builder respMsg = FireWorkProto.FireWorkRedPacketTableRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_FIREWORK_RP_ENTER, respMsg);
        }else{
            FireWorkProto.CrossFireWorkTableRedPacketReqMsg.Builder msg = FireWorkProto.CrossFireWorkTableRedPacketReqMsg.newBuilder();
            msg.setActivityId(activityId);
            msg.setIsGetGhost(isGetGhost);
            msg.addAllPage(reqMsg.getPageList());
            YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C2_FIREWORK_ACTIVITY_TABLE, msg);
            GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
        }
    }
}
